package howework.demo04;


import java.io.BufferedReader;
import java.io.InputStreamReader;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
public class CheckEmail {
   
public static void validate(String email)
{
if ( !(email.equals("q")) )
{ 
int firstAt=email.indexOf("@", 0);
int lastAT=email.lastIndexOf("@");
if (firstAt==0 || lastAT==( email.length()-1 ) || (firstAt==-1) || (firstAt!=lastAT) )
{
System.out.print("这不是合法的email地址");
}
else
{
System.out.print("这是合法的email地址");
}
}
}

public static void main(String s[]) 
{
System.out.print("请输入email地址. 输入 q 停止检验");
String email="";
try
{
while( !(email.equals("q")) )
{ 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
email=br.readLine();
validate(email);
}
}
catch(Exception e)
{
System.out.print("请输入一个email地址");
}
}
}


    
